﻿package src.flip{
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.media.*;
	import flash.net.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	import src.events.*;
	import src.utils.*;
	public final class Bar extends MovieClip {
		
		private var flip:Flip = Flip.flip;
		private var config:Object = Flip.config;
		
		private var BUTTONS:Object = {
			bt_left : FlipEvent.PAGE_PREV,
			bt_right : FlipEvent.PAGE_NEXT,
			bt_prev : FlipEvent.PAGE_PREV,
			bt_next : FlipEvent.PAGE_NEXT,
			bt_first : FlipEvent.PAGE_FIRST,
			bt_last : FlipEvent.PAGE_LAST,
			bt_print : FlipEvent.PRINT,
			bt_help : FlipEvent.HELP
		};
		
		public function Bar():void {

			//===============================
			flip.addEventListener(FlipEvent.RESIZE, resizeHandler);
			//
			flip.addEventListener(FlipEvent.PRINT, printHandler);
			flip.addEventListener(FlipEvent.HELP, helpHandler);
			//
			setButtons();
			resizeHandler();
		}

		private function printHandler(e:FlipEvent = null):void {
			
		}
		private function helpHandler(e:FlipEvent = null):void {
			
		}
		
		private function setButtons():void {
			for (var btn:String in BUTTONS) {
				var bt:SimpleButton = this[btn];
				//Debug.show(bt.name);
				bt.addEventListener(MouseEvent.CLICK, clickHandler);
			}
		}
		
		private function clickHandler(e:MouseEvent):void {
			var bte:String = BUTTONS[e.target.name];
			Flip.sendEvent(bte);
		}
		
		private function resizeHandler(e:FlipEvent = null):void {
			this.x = (config['width'] - this.bar_back.width) * 0.5;
			this.y = (config['height'] - this.bar_back.height);
			//左右键
			this.bt_left.x = config['width'] * 0.5 - config['page_width'] - this.x - this.bt_left.width - config['page_margin'];
			this.bt_right.x = config['width'] * 0.5 + config['page_width'] - this.x + config['page_margin'];
			this.bt_left.y = this.bt_right.y = - (this.y + this.bar_back.height) * 0.5;
			//
			
		}
		
	}
}